package com.lazy.book.controller;

import com.lazy.book.pojo.system.pojo.dto.common.SelectorQueryDTO;
import com.lazy.book.pojo.system.pojo.vo.common.SelectorVO;
import com.lazy.book.service.system.CommonService;
import com.sz.core.common.entity.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lay
 * @since 2025-09-05
 */
@Tag(name = "通用接口")
@RestController
@RequestMapping("/common")
@RequiredArgsConstructor
@Slf4j
public class CommonController {

    private final CommonService commonService;

    @Operation(summary = "模板下载")
    @GetMapping("/download/templates")
    public void fileDownload(@RequestParam("templateName") String templateName, HttpServletResponse response) {
        try {
            commonService.tempDownload(templateName, response);
        } catch (Exception e) {
            log.error("模板下载失败", e);
        }
    }

    @Operation(summary = "文件下载")
    @GetMapping("/fileDownloadBySysFileId")
    public void fileDownloadBySysFileId(@RequestParam("sysFileId") Long sysFileId, HttpServletResponse response) {
        try {
            commonService.fileDownloadBySysFileId(sysFileId, response);
        } catch (Exception e) {
            log.error("文件下载失败", e);
        }
    }



    @Operation(summary = "多维选择器查询")
    @GetMapping("/selector")
    public ApiResult<SelectorVO> querySelector(SelectorQueryDTO dto) {
        return ApiResult.success(commonService.querySelector(dto));
    }

}
